package com.zhangxiaofanfan.hotcode.fourth.third;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author zhangxiaofanfan
 * @date 2024-06-26 20:33:33
 */
public class HotCode056 {
    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3};
        HotCode056 hotCode056 = new HotCode056();
        List<List<Integer>> subsets = hotCode056.subsets(nums);
        subsets.forEach(System.out::println);
    }

    private List<List<Integer>> result = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        result.add(new ArrayList<>());
        bfs(nums, 0, new ArrayList<>());
        return result;
    }

    public void bfs(int[] nums, int beginIndex, List<Integer> list) {
        for (int i = beginIndex; i < nums.length; i++) {
            list.addLast(nums[i]);
            result.add(new ArrayList<>(list));
            bfs(nums, i + 1, list);
            list.removeLast();
        }
    }
}
